<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>活动页</title>
    <link rel="stylesheet" href="styles/base.css">
    <link rel="stylesheet" href="styles/common.css">
    <link rel="stylesheet" href="styles/applyfor.css">
    <style>
        body{  display: flex;  flex-direction: column;  height: 100%;  }
        header{flex: 0 0 auto;  }
    </style>
</head>
<body>
    <header id="header">
        <span class="title_name">报名购买</span>
    </header>
    <section class="page" style="flex: 1 0 auto;">
        <div class="register">
            <form id="myForm">
                <div class="flex">
                	<div class="label icon-user">姓名：</div>
                    <input placeholder="请输入您的姓名" type="text" class="input name" required="required"/>
                    <span class='error error-name'>请输入姓名！</span>
                </div>
                <div class="flex">
                	<div class="label icon-phone">电话：</div>
                    <input placeholder="请输入您的电话" type="text" class="input tel" required="required"/>
                    <span class='error error-phone'>手机号错误！</span>
                </div>
                <div class="flex">
                	<div class="label icon-newspaper">年龄：</div>
                    <input placeholder="请输入您的年龄" type="text" class="input age" required="required"/>
                    <span class='error  error-age'>年龄错误！</span>
                </div>
                <p>课程：<span id="courseName"></span> 价格：<span id="courseMoney"></span></p>
                <button class="signup-btn" type="button">确认购买</button>
            </form>

        </div>
    </section>
	<div class="bottomtext">
		购买成功后，自动成为课代表，可发展新生/转介绍购买课程，下级成功转介绍新生，可获得50元奖励。
    </div>
<script type="text/javascript" src="js/zepto.min.js"></script>
    <script type="text/javascript" src="js/jweixin-1.4.0.js"></script>
    <script type="text/javascript" src="js/wxconfig.js"></script>
    <script type="text/javascript" src="js/md5.min.js"></script>
    <script src="https://cdn.bootcss.com/sweetalert/2.0.2/sweetalert.min.js"></script>
	<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript" src="js/common.js"></script>
    <script>
        changePx(); //改变根元素的px
        var getSearchObj = getSerch(location.search);
        ﻿configWeixin();
		var payData;
        $(function(){
            $('#courseName').html(decodeURI(getSearchObj.payName))
            $('#courseMoney').html(getSearchObj.payPrice)
            // 按钮提交
            $(".signup-btn").click(function(){
                var name=$(".name").val(),phone = $(".tel").val(),age = $(".age").val();
                if(!name){
                    $(".error-name").show();
                    return;
                }
                if( !(/^[1][3,4,5,7,8][0-9]{9}$/.test(phone))) {
                        $(".error-phone").show();
                        return;
                }
                if(!(/^[0-9]{1,2}$/.test(age))) {
                    $(".error-age").show();
                    return;
                }
                //var arrjson = {'name':name,'mobile':phone,'age':age,'openId':getSearchObj.openId,'payPrice':getSearchObj.payPrice,'goodsName':getSearchObj.payName}
                var arrjson = {'name':name,'mobile':phone,'age':age,'openId':getSearchObj.openId,'payPrice':getSearchObj.payPrice,'goodsName':getSearchObj.payName,'firstOpenId':getSearchObj.firstOpenId,'parentOpenId':getSearchObj.parentOpenId,'goodsId':getSearchObj.goodsId}
				$.ajax({
                    type: "POST",
                    contentType: "application/json;charset=UTF-8",
                    url: "http://api.ucmd.cn/renren-api/act/mdxactivitysign",
                    data:  JSON.stringify(arrjson),
                    dataType: 'json',
                    success: function(result) {
                        if(result.code == 0) {
                            var data=result.data;
                           //swal('购买成功！');
                            var obj={'orderNo':data,'ip':returnCitySN["cip"]}
                            $.ajax({
                                type: "get",
                                contentType: "application/json;charset=UTF-8",
                                url: 'http://api.ucmd.cn/renren-api/wx/activity/wxc57d0b29494417fe/payOrder',
                                data:obj,
                                dataType: 'json',
                                success: function(result) {
                                    if(result.code == 0) {
										payData = result.data;
										wx.chooseWXPay({
											openId: getSearchObj.openId,
											timestamp: payData.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
											nonceStr: payData.nonceStr, // 支付签名随机串，不长于 32 位
											package: payData.packageValue, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
											signType: payData.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
											paySign: payData.paySign, // 支付签名
											success: function (res) {
												swal("支付成功");
												window.history.back();
											}
										});
                                    }else{
                                        swal(result.msg);
                                    }
                                }
                            })
                        } else {
                            swal(result.msg);
                        }
                    }
                });
            })
        })
		
    </script>
</body>
</html>